package xupt.se.ttms.view.movie;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.*;

import xupt.se.ttms.model.Movie;
import xupt.se.ttms.service.MovieSrv;
import xupt.se.ttms.view.employee.Employee_MainUITmpl;
public class UpdateMovie{
	
	private static 	String user="";
	private static Movie movie=null;
	protected static String imgurl="";
	public UpdateMovie(String user,Movie movie)
	{
		this.user=user;
		this.movie=movie;
		Init();
	}
	public static void Init(){
		JFrame p= new JFrame();
		p.setTitle("小霸王影院");
		p.setLayout(null);
		JPanel jp= new JPanel();
		p.setSize(800,500);
		jp.setLayout(null);
		jp.setBounds(0, 0, 850, 500);
		jp.setBackground(Color.decode("#FFE4C4"));
		ImageIcon icon = new ImageIcon(movie.getImg());
		//icon.setImage(icon.getImage().getScaledInstance(850, 60, Image.SCALE_DEFAULT));
		JLabel jj1= new JLabel(icon);
		jj1.setBounds(75, 75, 150,200);
		jj1.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void mousePressed(MouseEvent e) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void mouseExited(MouseEvent e) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void mouseEntered(MouseEvent e) {
				// TODO 自动生成的方法存根
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				JFileChooser jfc = new JFileChooser();
				
		   	     if(jfc.showOpenDialog(p)==JFileChooser.APPROVE_OPTION ){
		   	     File file=jfc.getSelectedFile();
		   	     String URL=file.getPath();
					 ImageIcon image = new ImageIcon(URL);
		             jj1.setIcon(image);
	   	     }
				
			}
		});
		jp.add(jj1);
		JLabel j1 =new JLabel("名称:");
		j1.setFont(new Font("宋体", Font.BOLD, 20));
		j1.setBounds(310,75,55,25);
		jp.add(j1);
		JLabel j2= new JLabel("导演:");
		j2.setFont(new Font("宋体", Font.BOLD, 20));
		j2.setBounds(310,100,55,25);
		jp.add(j2);	
		JLabel j3= new JLabel("主演:");
		j3.setFont(new Font("宋体", Font.BOLD, 20));
		j3.setBounds(310,125,55,25);
		jp.add(j3);
		JLabel j4= new JLabel("类型:");
		j4.setFont(new Font("宋体", Font.BOLD, 20));
		j4.setBounds(310,150,55,25);
		jp.add(j4);
		JLabel j5= new JLabel("评分:");
		j5.setFont(new Font("宋体", Font.BOLD, 20));
		j5.setBounds(310,175,55,25);
		jp.add(j5);	
		JLabel j6= new JLabel("时长:");
		j6.setBounds(310,200,55,25);
		j6.setFont(new Font("宋体", Font.BOLD, 20));
		jp.add(j6);
		JLabel j7= new JLabel("上映日期:");
		j7.setFont(new Font("宋体", Font.BOLD, 20));
		j7.setBounds(268,225,105,30);
		jp.add(j7);
		JLabel j8= new JLabel("剧情简介:");
		j8.setFont(new Font("宋体", Font.BOLD, 20));
		j8.setBounds(268,250,105,25);
		jp.add(j8);
		JTextField t1= new  JTextField();
		t1.setBounds(362,75, 150,22);
		jp.add(t1);
		JTextField t2= new  JTextField();
		t2.setBounds(362, 100, 150,22);
		jp.add(t2);
		JTextField t3= new  JTextField();
		t3.setBounds(362, 125, 150,22);
		jp.add(t3);
		JTextField t4= new  JTextField();
		t4.setBounds(362, 150, 150,22);
		jp.add(t4);
		JTextField t5= new  JTextField();
		t5.setBounds(362,175, 150,22);
		jp.add(t5);
		
		JTextField t6 = new JTextField();
		t6.setBounds(362, 200, 150, 22);
		jp.add(t6);
		JTextField t7 = new JTextField();
		t7.setBounds(362, 230, 150, 22);
		jp.add(t7);
		JTextArea t8= new  JTextArea();
		t8.setBorder(BorderFactory.createLineBorder(Color.decode("#c0c0c0")));
		t8.setBounds(362, 255, 150,99);
		t8.setWrapStyleWord(true);
		t8.setLineWrap(true);
		jp.add(t8);
		
		
		t1.setText(movie.getName());
		t2.setText(movie.getDirector());
		t3.setText(movie.getActor());
		t4.setText(movie.getType());
		t5.setText(String.valueOf(movie.getScore()));
		t6.setText(movie.getTime());
		t7.setText(String.valueOf(movie.getDate()));
		t8.setText(movie.getIntroduction());
		
		JFileChooser fc=new JFileChooser();
	    
		JButton b1 =new JButton("添加完成");
		
		b1.setFocusPainted(false);
		b1.setContentAreaFilled(false);
		b1.setBounds(362,365,150,50);
		b1.addActionListener(new ActionListener() {

	        @Override
	        public void actionPerformed(ActionEvent e) {
	        	if(UpdateMovie.imgurl.trim().equals(""))
	        	{
	        		JOptionPane.showConfirmDialog(null, "影片图片为空，添加失败");
	        		return;
	        	}
	        	if(t1.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片名称为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t2.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片导演为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t3.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片主演为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t4.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片类型为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t5.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片评分为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t7.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片上映日期为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	if(t8.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片简介为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        	
	        	if(t6.getText().trim().equals("")){
	        		//空的情况执行
	        		JOptionPane.showConfirmDialog(null, "影片时长为空，添加失败");
	        		return;
	        		}else{
	        		//不空的情况执行
	        		}
	        	String img=UpdateMovie.imgurl;
	        	String name=t1.getText();
	        	String director=t2.getText();
	        	String actor=t3.getText();
	        	String type=t4.getText();
	        	String score=t5.getText();       	
	        	String time=t6.getText();
	        	String date=t7.getText();
	        	String introduction=t8.getText();
	        	Movie movie =new Movie();
	        	movie.setMv_id(UpdateMovie.movie.getMv_id());
	        	movie.setImg(img);
	        	movie.setName(name);
	        	movie.setScore(Float.parseFloat(score));
	        	movie.setDirector(director);
	        	movie.setActor(actor);
	        	movie.setType(type);
	        	movie.setTime(time);
	        	movie.setDate(Integer.parseInt(date));
	        	movie.setIntroduction(introduction);
	        	MovieSrv movieSrv=new MovieSrv();
	        	try {
					movieSrv.modify(movie);
					if(Employee_MainUITmpl.jTable!=null)
					{
						Employee_MainUITmpl.jTable.updateUI();
					}
				} catch (Exception e1) {
					// TODO 自动生成的 catch 块
					e1.printStackTrace();
				}
	        	p.dispose();
	        	Employee_MainUITmpl employee_MainUITmpl=new Employee_MainUITmpl(user);

	        }}
	    });
		jp.add(b1);				      		
		p.add(jp);
		p.setLocationRelativeTo(null);
		p.setResizable(false);
		p.setVisible(true);
		}
	
}
